/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.esm.pdawms.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.esm.pdawms.R;
import com.esm.pdawms.database.manager.SystemCenter;
import com.esm.pdawms.model.Cghp;

import java.util.ArrayList;

import zuo.biao.library.base.BaseView;
import zuo.biao.library.model.Entry;
import zuo.biao.library.util.StringUtil;

public class CghpView extends BaseView<Entry<Integer, String>> implements View.OnClickListener {
    private static final String TAG = "CghpView";

    public CghpView(Activity context, ViewGroup parent) {
        super(context, R.layout.cghp_view, parent);
    }

    public TextView tv_hpname;
    public TextView tv_hegenum;
    public TextView tv_badnum;
    public TextView tv_rknum;
    public TextView tv_ynum;

    @Override
    public View createView() {
        tv_hpname = findView(R.id.tv_hpname);
//        tv_hpname = findView(R.id.tv_hpname, this);
        tv_hegenum = findView(R.id.tv_hegenum);
        tv_badnum = findView(R.id.tv_badnum);
        tv_rknum = findView(R.id.tv_rknum);
        tv_ynum = findView(R.id.tv_ynum);
        return super.createView();
    }

    @Override
    public void bindView(Entry<Integer, String> data_) {
        super.bindView(data_ != null ? data_ : new Entry<Integer, String>());
        itemView.setBackgroundResource(selected ? R.drawable.alpha3 : R.drawable.white_to_alpha);
        int index = data.getKey();
        ArrayList<Cghp> cghpList = SystemCenter.getInstance().cghpList;
        if (index < cghpList.size()) {
            Cghp cghp = cghpList.get(index);
            tv_hpname.setText(cghp.getHpcode() + "\n" + cghp.getHpname() + "\n批号：" + cghp.getPh() + "\n流水号：" + cghp.getLsh()+ "\n需求总数：" + cghp.getNum() + "");
            tv_hegenum.setText(cghp.getYdbqnum() + "");// 合格数
            tv_badnum.setText(cghp.getBadnum() + "");//不合格数
            tv_rknum.setText(cghp.getYrknum() + "");//已入库数
            tv_ynum.setText(cghp.getYnum() + "");//待检数
        }
    }

    @Override
    public void onClick(View v) {
        if (data == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.tv_hpname:
//			data.setKey("New " + data.getKey());
//			bindView(data);
//			if (onDataChangedListener != null) {
//				onDataChangedListener.onDataChanged();
//			}
                break;
            default:
                break;
        }
    }
}
